<%args>
  $cd_id        => ''
  $ci_req       => ''
  $ci_key       => ''
  $ci_name      => ''
  $ci_pos       => ''
  $ci_opt       => ''
  $ci_default   => ''
  $old_key_name => ''
  $list_ns      => ''
  $key_name     => ''
  $cd_name      => ''

  $app_back   => 0
  $app_delete => 0
  $app_clear  => 0
  $app_save   => 0
</%args>
<%attr>
  a_module => 'admin'
</%attr>
<%init>
  my $inkey_type_values = [ '', '(opt) =', '(opt) <=', '(opt) <', '(opt) >=', '(opt) >', '(opt) like', 'substitution', 'use default' ];
  my $inkey_type_labels = { '' => '', '(opt) =' => '(opt) =', '(opt) <=' => '(opt) <=', '(opt) <' => '(opt) <', '(opt) >=' => '(opt) >=', '(opt) like' => '(opt) like', 'substitution' => 'substitution', 'use default', => 'use default' };

  my $title = 'DIO InKey Editor - ' . $cd_name;

  if ($key_name) {
    my $d = LsL::D_DIO::get_dio_inkey({ci_name => $key_name, cd_id => $cd_id});
    $ci_name    = $d->{'ci_name'};
    $ci_req     = $d->{'ci_req'};
    $ci_default = $d->{'ci_default'};
    $ci_pos     = $d->{'ci_pos'};
    $ci_key     = $d->{'ci_key'};
    $ci_opt     = $d->{'ci_opt'};
  }

  # submit checks
  if ($app_save) {
    my ($req,$key);
    $req = '1' if $ci_req;
    $key = '1' if $ci_key;

    if ($old_key_name) {
      # update
      LsL::D_DIO::dio_inkey_update({cd_id => $cd_id,
                                     old_name => $old_key_name,
                                     ci_name => $ci_name,
                                     ci_pos => $ci_pos,
                                     ci_default => $ci_default,
                                     ci_req => $req, ci_key => $key,
                                     ci_opt => $ci_opt});
    } else {
      LsL::D_DIO::dio_inkey_insert({cd_id => $cd_id,
                                     ci_name => $ci_name,
                                     ci_pos => $ci_pos,
                                     ci_default => $ci_default,
                                     ci_req => $req, ci_key => $key,
                                     ci_opt => $ci_opt});
    }
    $m->comp( '/lib/refresh_box', 'title' => 'DIO InKey Saved...', 'path' => '/admin/lab/dio/inkey.html', 'query' => { 'cd_id' => $cd_id, 'list_ns' => $list_ns, 'cd_name' => $cd_name } );
    return;
  } elsif ($app_delete) {
    LsL::D_DIO::dio_inkey_delete({cd_id => $cd_id,
                                   ci_name => $old_key_name});
    $m->comp( '/lib/refresh_box', 'title' => 'DIO InKey Deleted...', 'path' => '/admin/lab/dio/inkey.html', 'query' => { 'cd_id' => $cd_id, 'list_ns' => $list_ns, 'cd_name' => $cd_name } );
    return;
  }

  # grab dio
  my $items  = {};

  $items  = LsL::D_DIO::get_dio_inkeys( { 'cd_id' => $cd_id } ) if $cd_id;
</%init>
<div class="grid_7">
<form method="POST" name="i_form" action="/admin/lab/dio/inkey.html">
<&| /lib/box-fs, title => $title, btype => 7 &>
<input type="hidden" name="cd_id" value="<% $cd_id %>" />
<input type="hidden" name="cd_name" value="<% $cd_name %>" />
<input type="hidden" name="list_ns" value="<% $list_ns %>" />
<input type="hidden" name="old_key_name" value="<% $key_name %>" />
<table class="no_color" border="0" cellpadding="4" cellspacing="0" width="100%">
<tr>
<td colspan="6" align="left" nowrap>
<input type="button" name="app_back" value="Back" class="button" onclick="location.replace('<& /lib/url, path => '/admin/lab/dio/edit.html', query => {cd_id => $cd_id, list_ns => $list_ns} &>');" />
% if ($key_name) {
<input type="submit" class="button" name="app_delete" value="Delete" />
% }
<input type="button" class="button" name="app_clear" value="Clear" onclick="location.replace('<& /lib/url, path => '/admin/lab/dio/inkey.html', query => {cd_id => $cd_id, list_ns => $list_ns, cd_name => $cd_name} &>');" />
<input type="submit" class="button" name="app_save" value="Save" />
</td>
</tr>
<tr class="header">
<td align="left" colspan="6">General</td>
<td align="right" valign="middle">
</td>
</tr>
</table>
<table class="no_color" id="log_tab" border="0" cellpadding="4" cellspacing="0" width="100%">
<tr class="lt">
<td align="left" valign="middle" width="1"><nobr>Name:</nobr></span><br></td>
<td colspan="2" align="left" valign="middle">
<input type="text" name="ci_name" size="40" value="<% $ci_name %>" />
</td>
</tr>
<tr class="dk">
<td align="left" valign="middle" width="1"><nobr>Position:</nobr></span><br></td>
<td colspan="2" align="left" valign="middle"><input type="text" name="ci_pos" size="5" value="<% $ci_pos %>" />&nbsp;<input type="checkbox" name="ci_key" value="1" <% ($ci_key ? 'checked="checked"':'') %> />Key&nbsp;<input type="checkbox" name="ci_req" value="1" <% ($ci_req ? 'checked="checked"':'') %> />Required</td>
</tr>
<tr class="lt">
<td align="left" valign="middle" width="1"><nobr>Type:</nobr></span><br></td>
<td colspan="2" align="left" valign="middle">
<& /lib/dropdown, 'name' => "ci_opt", 'value' => $ci_opt, 'values' => \@LAB::SysDIO::inkey_type_values, 'labels' => \%LAB::SysDIO::inkey_type_labels &>
</td>
</tr>
<tr class="dk">
<td align="left" style="vertical-align:top;" width="1" nowrap><nobr>Default / Tag:</nobr></span><br></td>
<td colspan="2" align="left" valign="middle">
<textarea name="ci_default" rows="5" cols="40" wrap="soft"><% $ci_default |h %></textarea>
</td>
</tr>
</table>
% if ($cd_id) {
<table class="lt_blue" border="0" cellpadding="4" cellspacing="0" width="100%">
<tr class="header">
<td colspan="7" align="left"><a href="#">In Keys</a></td>
</tr>
<tr class="dk">
<td align="left"><b>Edit</b></td>
<td align="left"><b>Name</b></td>
<td align="left"><b>Position</b></td>
<td align="left"><b>Key</b></td>
<td align="left"><b>Required</b></td>
<td align="left"><b>Type</b></td>
<td align="left"><b>Default</b></td>
</tr>
%   my $rcnt = 0;
%   foreach my $k (@{ $items }) {
<tr class="<% ($rcnt++ % 2 ? 'dk' : 'lt') %>">
<td align="left" nowrap>
<a href="<& /lib/url, 'path' => '/admin/lab/dio/inkey.html', 'query' => {'list_ns' => $list_ns, 'cd_id' => $cd_id, 'key_name' => $k->{'ci_name'}, 'cd_name' => $cd_name} &>" onMouseOver="window.status='View/Edit InKey'; overlib('Click here to view/edit the InKey entry'); return true;" onMouseOut="window.status=''; nd(); return true;"><img alt="" src="/i/icons/index.gif" border="0"></a>
</td>
<td align="left"><% $k->{'ci_name'} %></td>
<td align="left"><% $k->{'ci_pos'} %></td>
<td align="left"><% ($k->{'ci_key'} || '-') %></td>
<td align="left"><% ($k->{'ci_req'} || '-') %></td>
<td align="left"><% $k->{'ci_opt'} %></td>
<td align="left"><% $k->{'ci_default'} %></td>
</tr>
%   }
</table>
% }
</&>
</form>
</div>
